/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "zobjects_gtk.h"

int CreateToolBar( struct ZlangRuntime *rt , struct ZlangDirectProperty_guitoolbar *guitoolbar_direct_prop )
{
	struct ZlangDirectProperty_guiwidget_common	*guitoolbar_common = (struct ZlangDirectProperty_guiwidget_common *)guitoolbar_direct_prop ;

	guitoolbar_common->gtk_widget = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0) ;
	if( guitoolbar_common->gtk_widget == NULL )
	{
		ThrowErrorException( rt , ZLANG_ERROR_ALLOC , EXCEPTION_MESSAGE_NEW_GTK_OBJECT_FAILED );
		return -1;
	}
	
	gtk_widget_set_valign( guitoolbar_common->gtk_widget , GTK_ALIGN_START );
	gtk_style_context_add_class( gtk_widget_get_style_context(guitoolbar_common->gtk_widget) , "toolbar" );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guitoolbar_guitoolbar_Create_guiwindow;
int ZlangInvokeFunction_guitoolbar_guitoolbar_Create_guiwindow( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	struct ZlangDirectProperty_guitoolbar		*guitoolbar_direct_prop = GetObjectDirectProperty(out1) ;
	struct ZlangDirectProperty_guiwidget_common	*guitoolbar_common = & (guitoolbar_direct_prop->common) ;
	int						nret = 0 ;

	nret = CreateToolBar( rt , guitoolbar_direct_prop ) ;
	if( nret )
	{
		UnreferObject( rt , out1 );
		return 0;
	}

	TRANSFER_INPUT_OBJECT_TO_NEW_OBJECT( guitoolbar_common->guiwindow_obj , in1 )

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guitoolbar_AddToolBarItem_object;
int ZlangInvokeFunction_guitoolbar_AddToolBarItem_object( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitoolbar		*guitoolbar_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guitoolbar_common = (struct ZlangDirectProperty_guiwidget_common *)guitoolbar_direct_prop ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	void						*guictl_direct_prop = GetObjectDirectProperty(in1) ;
	struct ZlangDirectProperty_guiwidget_common	*guictl_common = (struct ZlangDirectProperty_guiwidget_common *)guictl_direct_prop ;

	gtk_box_append( GTK_BOX(guitoolbar_common->gtk_widget) , guictl_common->gtk_widget );

	/*
	nret = RegisteControlToWindow( rt , guictl_common->guiwindow_obj , in1 ) ;
	if( nret )
	{
		CallRuntimeFunction_bool_SetBoolValue( rt , out1 , FALSE );
		QuitGtkMainLoop( guictl_common->guiwindow_obj );
		return nret;
	}
	*/

	CallRuntimeFunction_bool_SetBoolValue( rt , out1 , TRUE );
	return 0;
}

ZLANG_INVOKE_FUNCTION_guiwidget_all_common_functions( toolbar )

ZLANG_INVOKE_FUNCTION_guictl_all_common_functions( toolbar )

ZlangCreateDirectPropertyFunction ZlangCreateDirectProperty_guitoolbar;
void *ZlangCreateDirectProperty_guitoolbar( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitoolbar	*guitoolbar_prop = NULL ;
	
	guitoolbar_prop = (struct ZlangDirectProperty_guitoolbar *)ZLMALLOC( sizeof(struct ZlangDirectProperty_guitoolbar) ) ;
	if( guitoolbar_prop == NULL )
	{
		SET_RUNTIME_ERROR( rt , RUNTIME_ERROR , ZLANG_ERROR_ALLOC , "alloc memory for entity" )
		return NULL;
	}
	memset( guitoolbar_prop , 0x00 , sizeof(struct ZlangDirectProperty_guitoolbar) );

	INIT_ZLANGDIRECTPROPERTY_guiwidget_common(guitoolbar)
	
	return guitoolbar_prop;
}

ZlangDestroyDirectPropertyFunction ZlangDestroyDirectProperty_guitoolbar;
void ZlangDestroyDirectProperty_guitoolbar( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitoolbar	*guitoolbar_direct_prop = GetObjectDirectProperty(obj) ;
	
	CLEAN_ZLANGDIRECTPROPERTY_guiwidget_common(guitoolbar)

	ZLFREE( guitoolbar_direct_prop );
	
	return;
}

ZlangSummarizeDirectPropertySizeFunction ZlangSummarizeDirectPropertySize_guitoolbar;
void ZlangSummarizeDirectPropertySize_guitoolbar( struct ZlangRuntime *rt , struct ZlangObject *obj , size_t *summarized_obj_size , size_t *summarized_direct_prop_size )
{
	SUMMARIZE_SIZE( summarized_direct_prop_size , sizeof(struct ZlangDirectProperty_guitoolbar) )
	return;
}

static struct ZlangDirectFunctions direct_funcs_guitoolbar =
	{
		ZLANG_OBJECT_guitoolbar , /* char *ancestor_name */
		
		ZlangCreateDirectProperty_guitoolbar , /* ZlangCreateDirectPropertyFunction *create_entity_func */
		ZlangDestroyDirectProperty_guitoolbar , /* ZlangDestroyDirectPropertyFunction *destroy_entity_func */
		
		NULL , /* ZlangFromCharPtrFunction *from_char_ptr_func */
		NULL , /* ZlangToStringFunction *to_string_func */
		NULL , /* ZlangFromDataPtrFunction *from_data_ptr_func */
		NULL , /* ZlangGetDataPtrFunction *get_data_ptr_func */
		
		NULL , /* ZlangOperatorFunction *oper_PLUS_func */
		NULL , /* ZlangOperatorFunction *oper_MINUS_func */
		NULL , /* ZlangOperatorFunction *oper_MUL_func */
		NULL , /* ZlangOperatorFunction *oper_DIV_func */
		NULL , /* ZlangOperatorFunction *oper_MOD_func */
		
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_NEGATIVE_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_NOT_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_BIT_REVERSE_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_PLUS_PLUS_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_MINUS_MINUS_func */
		
		NULL , /* ZlangCompareFunction *comp_EGUAL_func */
		NULL , /* ZlangCompareFunction *comp_NOTEGUAL_func */
		NULL , /* ZlangCompareFunction *comp_LT_func */
		NULL , /* ZlangCompareFunction *comp_LE_func */
		NULL , /* ZlangCompareFunction *comp_GT_func */
		NULL , /* ZlangCompareFunction *comp_GE_func */
		
		NULL , /* ZlangLogicFunction *logic_AND_func */
		NULL , /* ZlangLogicFunction *logic_OR_func */
		
		NULL , /* ZlangLogicFunction *bit_AND_func */
		NULL , /* ZlangLogicFunction *bit_XOR_func */
		NULL , /* ZlangLogicFunction *bit_OR_func */
		NULL , /* ZlangLogicFunction *bit_MOVELEFT_func */
		NULL , /* ZlangLogicFunction *bit_MOVERIGHT_func */
		
		ZlangSummarizeDirectPropertySize_guitoolbar , /* ZlangSummarizeDirectPropertySizeFunction *summarize_direct_prop_size_func */
	} ;

ZlangImportObjectFunction ZlangImportObject_guitoolbar;
struct ZlangObject *ZlangImportObject_guitoolbar( struct ZlangRuntime *rt )
{
	struct ZlangObject	*obj = NULL ;
	struct ZlangFunction	*func = NULL ;
	int			nret = 0 ;
	
	nret = ImportObject( rt , & obj , ZLANG_OBJECT_guitoolbar , & direct_funcs_guitoolbar , sizeof(struct ZlangDirectFunctions) , NULL ) ;
	if( nret )
	{
		SET_RUNTIME_ERROR( rt , RUNTIME_ERROR , ZLANG_ERROR_LINK_FUNC_TO_ENTITY , "import object to global objects heap" )
		return NULL;
	}
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guitoolbar_guitoolbar_Create_guiwindow , ZLANG_OBJECT_guitoolbar , "Create" , ZLANG_OBJECT_guiwindow,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	ADD_FUNCTION_AND_PARAMETERS_IN_OBJECT_guiwidget_all_common_functions( toolbar )

	ADD_FUNCTION_AND_PARAMETERS_IN_OBJECT_guictl_all_common_functions( toolbar )

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guitoolbar_AddToolBarItem_object , ZLANG_OBJECT_bool , "AddToolBarItem" , ZLANG_OBJECT_object,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	return obj ;
}
